<?php
namespace app\home\Controller;

use app\common\controller\Base;
use app\common\model\Article;
use app\common\model\User;
use app\common\model\Cate;
use app\common\model\Comment;
use think\facade\Request;
use think\Db;

class Index extends Base
{
	
    public function index()
    {
		return view();
    }
	


	//搜索功能
	public function search()
	{
		$this->showUser();
        //全局查询条件
        $map = []; //所有的查询条件封装到数组中
        //条件1：
        $map[] = ['status','=',1]; //这里等号不能省略

        //实现搜索功能
        $keywords = input('keywords');
        if(!empty($keywords)){
			//条件2
            $map[] = ['title','like','%'.$keywords.'%'];
			$artList = Article::withCount('user,comments')->where($map)->order('create_time','desc')->paginate(10);
			$counts = count($artList); 
			$searchs = [
				'artList' => $artList,
				'keywords' => $keywords,
				'counts' => $counts
			];
			//$this->assign('keywords',$keywords);
			$this->assign($searchs);
		
		//	查询热议
		$artHot = Article::where('status',1)->where('is_hot',1)->order('create_time','desc')->limit(10)->select();
		$this->assign('artHot',$artHot);
			    	
        } else{
			return '请输入关键词';
		}
		return view('search');
	}



}
